package com.xy.user.service;


import com.xy.core.exception.ClassCheckException;
import com.xy.user.base.service.BaseService;
import com.xy.user.domain.Xyuser;
import com.xy.user.persistence.XyuserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * 用户
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class XyuserService extends BaseService<Xyuser> {
    @Autowired
    private XyuserMapper xyuserMapper;

    @Autowired
    public void setBaseMapper(XyuserMapper xyuserMapper) {
        this.baseMapper = xyuserMapper;
    }


    public void checkEntity(Xyuser xyuser) throws ClassCheckException {
        if(xyuser.getUserId()!=null&&xyuser.getUserId().length()>19){
            throw new ClassCheckException("用户用户id不能超过19个字符");
        }
        if(xyuser.getUsername()!=null&&xyuser.getUsername().length()>19){
            throw new ClassCheckException("用户用户名不能超过19个字符");
        }
        if(xyuser.getPassword()!=null&&xyuser.getPassword().length()>32){
            throw new ClassCheckException("用户密码不能超过32个字符");
        }
        if(xyuser.getNickname()!=null&&xyuser.getNickname().length()>19){
            throw new ClassCheckException("用户昵称不能超过19个字符");
        }
        if(xyuser.getIp()!=null&&xyuser.getIp().length()>19){
            throw new ClassCheckException("用户用户登录ip地址不能超过19个字符");
        }
    }
    public void checkListEntity(List<Xyuser> listXyuser) throws ClassCheckException {

        for (Xyuser xyuser : listXyuser) {
            checkEntity(xyuser);
        }

    }
    public Xyuser getByUsername(String username){
        return xyuserMapper.getByUsername(username);
    }

    public List<Map<String,Object>> allListpersimission(String roleId){
        return xyuserMapper.allListpersimission(roleId);
    }
}
